package com.whz.tagclass;

/**
 * @Author: sinosoft
 * @Description: 标签类 过于冗长 容易出错 并且效率低下
 * @Date: Create in 19:21 2021/5/10
 * @Modified By:
 */
public class Figure {
    enum Shape { RECTANGLE, CIRCLE };
    final Shape shape;
    /*当且仅当图形是长方形时被使用*/
    double length;
    double width;
    /*当且仅当图形是圆时被使用*/
    double radius;

    /*圆初始化*/
    public Figure(double radius) {
        shape = Shape.CIRCLE;
        this.radius = radius;
    }

    /*长方形初始化*/
    public Figure(double length, double width) {
        shape = Shape.RECTANGLE;
        this.length = length;
        this.width = width;
    }

    double area() {
        switch (shape) {
            case CIRCLE:
                return Math.PI * (radius * radius);
            case RECTANGLE:
                return length * width;
            default:
                throw new AssertionError(shape);
        }
    }
}
